//
//  inquiryViewController.swift
//  NewLndd
//
//  Created by 邵禹曦 on 2020/1/8.
//  Copyright © 2020 辽宁当代. All rights reserved.
//

import UIKit
// MARK: - 查询
class inquiryViewController: ApiViewController {
    var _comInfo : String?
    @IBOutlet weak var wcjcx: UIView!
    @IBOutlet weak var ycjcx: UIView!
    @IBOutlet weak var ycdcx: UIView!
    @IBOutlet weak var zdjlcx: UIView!
    @IBOutlet weak var cjmx: UIView!
    
    @IBOutlet weak var SegmentClick: UISegmentedControl!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        showInfo()
        self.showTabBtn()
    }
    

    @IBAction func BtnSegmentClick(_ sender: Any) {
        switch SegmentClick.selectedSegmentIndex {
            case 0:
                wcjcx.isHidden = false
                ycjcx.isHidden = true
                ycdcx.isHidden = true
                zdjlcx.isHidden = true
                //cjmx.isHidden = true
            case 1:
                wcjcx.isHidden = true
                ycjcx.isHidden = false
                ycdcx.isHidden = true
                zdjlcx.isHidden = true
                //cjmx.isHidden = true
            case 2:
                wcjcx.isHidden = true
                ycjcx.isHidden = true
                ycdcx.isHidden = false
                zdjlcx.isHidden = true
                //cjmx.isHidden = true
            case 3:
                wcjcx.isHidden = true
                ycjcx.isHidden = true
                ycdcx.isHidden = true
                zdjlcx.isHidden = false
                //cjmx.isHidden = true
            default:
                break;
        }
    }
    
}


extension inquiryViewController{
    private func showInfo() {
           // GCD
           let group = DispatchGroup()
    
           // 从沙盒中获取参数
            var userPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
            userPath =  (userPath as NSString).appendingPathComponent("data.plist")
            user = NSKeyedUnarchiver.unarchiveObject(withFile: userPath) as? User


           // 用户验证
           self.u = user?.U!
           self.retcode = user?.RETCODE!
           // 用户验证
           let str = [u,"101",retcode]
            
           //self.isLogin = self._network(str: str as! [String], group: group)
        group.enter()
        NetworkTools.share.check_user(code: str as Array<Any>) { (result, error) in
                      
                          if error != nil {
                              print("no no no")
                              return
                          }
                          

                          if Int(self._retcode(res: result!))! < 0 {
                              self.isLogin = false
                          } else {
                              self.isLogin = true
                          }
                          group.leave()
                      }

           group.notify(queue: DispatchQueue.main) {
               if !self.isLogin {
                if #available(iOS 13.0, *) {
                    self._alertVisitorView()
                }
                return
               } else {
                   // 2.设置导航栏内容
                    //self.tableShouInfo()
               }
            }
       }
    
    // 按钮控制tableView
    @objc private func showTabBtn() {
        wcjcx.isHidden = false
        ycjcx.isHidden = true
        ycdcx.isHidden = true
        zdjlcx.isHidden = true
    }
}
